package campus.service.impl;

import campus.mapper.MenuMapper;
import campus.mapper.UserMapper;
import campus.model.Menu;
import campus.model.User;
import campus.model.UserExample;
import campus.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author VULCAN
 * @create 2020-05-06 22:27
 * @desc  实现
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private MenuMapper menuMapper;
    @Override
    public List<User> selectByExample(UserExample example) {
        return userMapper.selectByExample(null);
    }

    @Override
    public List<Menu> findMenu(String id) {
        return menuMapper.findMenu(id);
    }

    @Override
    public User login(User user) {
        return userMapper.login(user);
    }

    @Override
    public int zhuce(User user) {
        user.setUserId(UUID.randomUUID().toString());
        user.setUserCdate(new Date());
        return userMapper.insert(user);
    }

    @Override
    public void cz(User user) {
        User selectemail = userMapper.selectemail(user.geteMail());
        User user1 = new User();
        user1.setUserId(selectemail.getUserId());
        user1.setUserPwd(user.getUserPwd());
        userMapper.update(user1);
    }
    /**
     * 查询单个
     * @param id
     * @return
     */
    @Override
    public User findById(String id) {
        return userMapper.findById(id);
    }

    /**
     * 修改个人信息
     * @param user
     */
    @Override
    public void userupdate(User user) {
        userMapper.updateByExample(user,null);
    }
}
